#include <iostream>
#include <string>
using namespace std;

struct Hero{
    string name;
    int age;
    string sex;
};


void bubbleSort(struct Hero hero[],int len){
    for(int i=0;i<len;i++){
        for(int j=0;j<len-i-1;j++){
            if (hero[j].age>hero[j+1].age){
                struct Hero heroTemp=hero[j];
                hero[j]=hero[j+1];
                hero[j+1]=heroTemp;
            }
        }
    }
};


void printHero(struct Hero hero[],int len){
    for(int i=0;i<len;i++){
        cout<<"英雄名称: "<<hero[i].name<<"英雄年龄: "<<hero[i].age<<"英雄性别: "<<hero[i].sex<<endl;
    }
}

int main(){
    struct Hero hero[]={
        {"刘备",25,"男"},
        {"张飞",23,"男"},
        {"关飞",22,"男"},
        {"赵云",26,"男"},
        {"貂蝉",19,"女"}
    };

    cout<<"排序前"<<endl;
    int len=sizeof(hero)/sizeof(hero[0]);
    printHero(hero,len);
    bubbleSort(hero,len);
    cout<<"排序后"<<endl;
    printHero(hero,len);
    return 0;
}
